﻿using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;
using WMS.BasicData.Vendors.DTO;
using WMS.InventoryManagement.Differences;
using WMS.InventoryManagement.Differences.DTO;
using WMS.Web.Controllers.BasicData.Vendors;

namespace WMS.Web.Controllers.InventoryManagement.Differences
{
    public class DifferenceController : Controller
    {
        private readonly IDifferencesAppService _differences;

        public DifferenceController(IDifferencesAppService differences)
        {
            _differences = differences;
        }

        public IActionResult DifferenceIndex()
        {
            return View();
        }

        [HttpGet]
        public JsonResult GetDifference(string? stocker, int page, int limit)
        {
            var pagedResult = _differences.GetListAsync(stocker, page, limit);
            return Json(new { data = pagedResult, code = 0 });
        }

        public IActionResult DifferenceAddIndex()
        {
            return View();
        }

        [HttpPost]
        public JsonResult AddDifference(Difference input)
        {
            var arealist = _differences.CreateAsync(input);
            return Json(new { code = arealist, msg = "添加成功" });
        }

        /// <summary>
        /// 删除数据
        /// </summary>
        /// <returns>返回对应数据</returns>
        [HttpPost]
        public JsonResult DifferenceDelete(int id)
        {
            var arealist = _differences.DeleteAsync(id);
            return Json(new { code = arealist, msg = "删除成功" });
        }

        public ActionResult DifferenceUpdateIndex(int id)
        {
            ViewBag.Id = id;
            return View();
        }

        [HttpGet]
        public JsonResult GetDifferenceById(int id)
        {
            var arealist = _differences.GetDifferenceById(id);
            return Json(new { data = arealist, code = 0 });
        }

        [HttpPost]
        public JsonResult UpdateDifference(UpdateDifferentDTO input)
        {
            var arealist = _differences.UpdateAsync(input);
            return Json(new { code = true, data = arealist });
        }

    }
}
